package SingletonMode;

/**
 * @program: DesignModeProject
 * @description: 饿汉模式（静态代码块）
 * @author: Li canzhang
 * @create: 2022-04-09 21:43
 **/
public class SingletonTest02 {
    public static void main(String[] args) {
        Singleton02 inst1 = Singleton02.getInst();
        Singleton02 inst2 = Singleton02.getInst();

        System.out.println(inst1.hashCode());
        System.out.println(inst2.hashCode());

    }
}

class Singleton02{
    private final static Singleton02 inst;

    static {
        inst = new Singleton02();
    }

    //构造器私有化
    private Singleton02(){

    }

    //提供一个公共方法获取类实例
    public static Singleton02 getInst(){
        return inst;
    }
}
